//
//  LBCategoryHeaderViewModel.m
//  AFNetworking
//
//  Created by luckyRoy on 2017/12/21.
//

#import "LBCategoryHeaderViewModel.h"
#import "LBCategorySettingModel.h"

@implementation LBCategoryHeaderViewModel

+ (LBCategoryHeaderViewModel *)headerModelBySection:(NSInteger)section
                                       settingModel:(LBCategorySettingModel *)settingModel
                                         viewLayout:(LBCategoryMainViewLayout *)viewLayout
                                      selectedModel:(LBCategoryModel *)model
{
    LBCategoryHeaderViewModel *resultModel = [[LBCategoryHeaderViewModel alloc]init];
    
    BOOL isHideEditorButton = YES;
    
    NSString *topTitle = nil;
    
    NSString *bottomTitle = model.parName;
    
    if ([LBCategorySettingModel isBookingViewByCodeType:settingModel.codeType] &&
        LBCategorySettingPageTypeHomePage == viewLayout.pageType) {
        if (0 == section) {
            isHideEditorButton = NO;
            topTitle = @"我的订阅";
            bottomTitle = nil;
        } else if (1 == section && model) {
            //未订阅有数据才展示段头
            NSString *smallStr = @"点击下方分类添加订阅";
            topTitle = [NSString stringWithFormat:@"添加订阅 %@",smallStr];
            NSRange smallRange = [topTitle rangeOfString:smallStr];
            NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:topTitle];
            [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:smallRange];
            [attr addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:smallRange];
            resultModel.title = attr;
        }
    }
    
    resultModel.isHideEditorButton = isHideEditorButton;
    
    if (!isHideEditorButton) {
        resultModel.isEditor = settingModel.isEdiotr;
    }
    
    if (!resultModel.title.length && topTitle.length) {
        resultModel.title = [[NSMutableAttributedString alloc]initWithString:topTitle];
    }
    
    if (bottomTitle.length) {
        resultModel.content = [[NSMutableAttributedString alloc]initWithString:bottomTitle];
    }
    
    resultModel.categoryUrl = model.parLogo;

    return resultModel;
}

+ (LBCategoryHeaderViewModel *)partHeaderModelParName:(NSString *)categoryName
{
    LBCategoryHeaderViewModel *resultModel = [[LBCategoryHeaderViewModel alloc]init];
    
    resultModel.isHideEditorButton = YES;
 
    resultModel.title = nil;
    resultModel.content = [[NSMutableAttributedString alloc]initWithString:categoryName];
    
    return resultModel;
}

@end
